home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / bldproj / bp.c next >
Text File  |  1988-01-06  |  2KB  |  113 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <dir.h>            /* findfirst/next & struct ffblk */
  4.  
  5. /*****************************************************************
  6. ** build turboc project file from files in arg list
  7. ** buildproject  mine.prj  misc.c this.c that.c etc.c
  8. **
  9. ** 1/6/87 -Ejm
  10. **
  11. ******************************************************************/
  12.  
  13. #define        TRUE    1
  14. #define        FALSE    0
  15.  
  16. main(argc,argv)
  17. int argc;
  18. char *argv[];
  19. {
  20.        FILE *project;
  21.        int n;
  22.        char Buf[80+1];
  23.     struct ffblk fdir;
  24.  
  25.     if(argc<2)
  26.     {
  27.          printf("Usage %s  FILE.PRJ  [name.c] [name.c] etc...\n",argv[0]);
  28.          printf("Create TURBOC Project File From C sources  1/6/87 -Ejm\n");
  29.          exit(1);
  30.     }
  31.  
  32.     if(argc<3)
  33.     {
  34.         argv[argc] = "*.c";
  35.         argc++;
  36.     }
  37.  
  38.     if( (project=fopen(argv[1],"w+t")) ==NULL)
  39.     {
  40.         sprintf(Buf,"%s Cant Open File %s",argv[0],argv[1]);
  41.          perror(Buf);
  42.          exit(1);
  43.     }
  44.     
  45.     for(n=2; n<argc; n++)
  46.     {
  47.         if( findfirst(argv[n],&fdir,0) == 0 )
  48.         {
  49.             do
  50.             {
  51.                 build(project,fdir.ff_name);
  52.             }while( findnext(&fdir) == 0 );
  53.         }
  54.     }
  55.     fcloseall();
  56.  
  57.     exit(0);    
  58. }
  59.  
  60.  
  61. build(fo,s)
  62. FILE *fo;
  63. char *s;
  64. {
  65.     FILE *fi;
  66.     char line[512+1];
  67.     char delim, *p, name[80+1];
  68.     int n;
  69.     int iflag = FALSE;
  70.  
  71.     fi = fopen(s,"rt");
  72.     if(fi==NULL)
  73.     {
  74.         printf("File %s Skipped ...");
  75.         perror("");
  76.         return;
  77.     }
  78.  
  79.     fprintf(fo,"%s",s);
  80.     printf("Scanning File  %s For #include...",s);
  81.  
  82.     while( feof(fi) == FALSE )
  83.     {
  84.         fgets(line,512,fi);
  85.         n = sscanf(line,"#include %c%s",&delim,name);
  86.  
  87.         if(n==2 && delim!='<')     /* ignore files in <stdlib.h> */
  88.         {
  89.             p = strpbrk(name,"\">");
  90.             if(p!=NULL)
  91.                 *p=NULL;            /*remove closing bracket or quote */
  92.  
  93.             if(iflag==FALSE)
  94.             {
  95.                 iflag=TRUE;
  96.                 fprintf(fo," (");        
  97.             }
  98.             else
  99.                 fprintf(fo," ");
  100.  
  101.             fprintf(fo,"%s",name);
  102.         }
  103.     }
  104.     if(iflag==TRUE)
  105.         fprintf(fo,")");
  106.  
  107.     fprintf(fo,"\n");
  108.     printf("\n");
  109.  
  110.     fclose(fi);
  111. }
  112.  
  113.